/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = __frshm_stat_new.c                                 */
/*  NOTE      =                                                    */
/*  DATE      = 2016/04/14 by jikw                                 */
/*******************************************************************/

#include <CUnit/Basic.h>
#include <stdlib.h>

#include "frcomm.h"
#include "frmem.h"
#include "conntrack.h"
#include "frct_comm.h"
#include "../../../src/lib/apmshm/frshm_stat.h"

#include "apmtest_comm.h"

static int __suite_init(void)
{

    return 0;
}

static int __suite_cleanup(void)
{

    return 0;
}

extern int __frshm_stat_new(int i_shmid, int i_new_shmid, char *p_name
                   , int i_pool_size, int i_shm_size
                   , int *p_i_index);

static void case1(void)
{
    int i_ret = 0;
    int i_new = 500;
    int i_index = 0;

    frshm_stat_exit();
    frshm_stat_init();
    frshm_stat_get();
    
    i_ret = __frshm_stat_new(-1, i_new, (char *)"dssl", 1000, 1000, &i_index);

    CU_ASSERT_EQUAL(i_ret, FR_FAIL);
    
    frshm_stat_exit();
    
    return;
}

static void case2(void)
{
    int i_ret = 0;
    int i_index = 0;

    frshm_stat_exit();
    frshm_stat_init();
    frshm_stat_get();
    
    i_ret = __frshm_stat_new(g_i_shm_stat_id, -1, (char *)"dssl", 1000, 1000, &i_index);
    
    CU_ASSERT_EQUAL(i_ret, FR_FAIL);
    
    frshm_stat_exit();
    
    return;
}

static void case3(void)
{
    int i_ret = 0;
    int i_index = 0;

    frshm_stat_exit();
    frshm_stat_init();
    frshm_stat_get();
    
    i_ret = __frshm_stat_new(g_i_shm_stat_id, 500, NULL, 1000, 1000, &i_index);
    
    CU_ASSERT_EQUAL(i_ret, FR_FAIL);
    
    frshm_stat_exit();
    
    return;
}

static void case4(void)
{
    int i_ret = 0;
    int i_index = -1;

    frshm_stat_exit();
    frshm_stat_init();
    frshm_stat_get();
        
    i_ret = __frshm_stat_new(g_i_shm_stat_id, 500, (char *)"dssl", 1000, 1000, &i_index);
   
    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_EQUAL(i_index, 0);
    
    frshm_stat_exit();
    
    return;
}

int add_suite__frshm_stat_new(void)
{
    CU_pSuite pSuite = NULL;
    
    if((pSuite = CU_add_suite("frcomm __frshm_stat_new()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    CU_add_test(pSuite, "case1", case1);
    CU_add_test(pSuite, "case2", case2);
    CU_add_test(pSuite, "case3", case3);
    CU_add_test(pSuite, "case4", case4);

    return FR_SUCC;
}
